package acciones;
import persistencia.PersonaDAO;
import persistencia.RevisorDAO;
import dominio.Persona;


public class IniciarSesion extends ComprobarSesion implements Constantes {

	private static final long serialVersionUID = 1L;
	private Persona persona;
	private String dni;
	private String password;
	private Exception excepcion;
	private String key;

	public String execute() {
		try {
			persona = PersonaDAO.validar(dni, password);
			String rol = persona.getRol();
			crearSesion("persona", persona);
			if (rol.equalsIgnoreCase(AUTOR)) {
				return AUTOR;
			} else if (rol.equalsIgnoreCase(EDITOR)) {
				return EDITOR;
			} else {
				key= RevisorDAO.getPclaves(dni);
				return REVISOR;
			}
		} catch (Exception e) {
			this.setExcepcion(e);
			return ERROR;
		}
	}

	public String getDni() {
		return dni;
	}

	public void setDni(String dni) {
		this.dni = dni;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Persona getPersona() {
		return persona;
	}

	public void setPersona(Persona cliente) {
		this.persona = cliente;
	}

	public Exception getExcepcion() {
		return excepcion;
	}

	public void setExcepcion(Exception excepcion) {
		this.excepcion = excepcion;
	}
	
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

}
